package com.runa.monitor.platinterface.mqtt.vo;

import com.runa.persistence.StringUtil;

/**
 * 2025/4/11 14:34
 * zhangYB
 */
public class FieldHandler {


    public Float getFirstFloatFromArrayStr(String s) {
        return Float.valueOf(getFirstStringFromArrayStr(s));
    }

    public String getFirstStringFromArrayStr(String s) {
        String[] split = getFromArrayStr(s);
        if (split.length == 0) {
            return null;
        }
        return split[0];
    }

    public Float getFromArrayStr(String[] strings, int index) {
        if (strings.length <= index + 1) {
            return null;
        }
        return Float.valueOf(strings[index]);
    }

    public String[] getFromArrayStr(String s) {
        if (StringUtil.isBlank(s)) {
            return null;
        }
        if (s.contains(",")) {
            return s.replace("[", "").replace("]", "").split(",");
        }
        return s.replace("[", "").replace("]", "").split("_");
    }


    public Float convertFloat(String s) {
        return null == s ? null : Float.valueOf(s);
    }

}
